//
//  SideMenuView.m
//  HDYS
//
//  Created by qianfeng on 15-4-21.
//  Copyright (c) 2015年 kay. All rights reserved.
//

#import "SideMenuView.h"

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

@interface SideMenuView () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSArray *contentArray;

@end

@implementation SideMenuView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.frame = frame;
        self.backgroundColor = [UIColor magentaColor];
        self.contentArray = @[@"收藏夹",@"钱包",@"已买到的宝贝",@"签到",@"优惠券"];
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, SCREEN_HEIGHT)];
    backImgView.image = [UIImage imageNamed:@"images.jpeg"];
    [self addSubview:backImgView];
    
    UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    iconBtn.frame = CGRectMake(25, 30, 64, 64);
    iconBtn.layer.cornerRadius = 32;
    [iconBtn setImage:[UIImage imageNamed:@"center_ball"] forState:UIControlStateNormal];
    [self addSubview:iconBtn];
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(iconBtn.frame.origin.x + iconBtn.frame.size.width + 10, iconBtn.frame.origin.y, 100, 20)];
    nameLabel.text = @"Kay";
    [self addSubview:nameLabel];
    
    UIImageView *sexImgView = [[UIImageView alloc] initWithFrame:CGRectMake(nameLabel.frame.origin.x + 5, nameLabel.frame.origin.y + nameLabel.frame.size.height + 10, 10, 15)];
    sexImgView.image = [UIImage imageNamed:@"ipadweiboMale"];
    [self addSubview:sexImgView];
    
    //侧边栏表视图
    UITableView *contentTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, iconBtn.frame.origin.y + iconBtn.frame.size.height + 15, self.frame.size.width - 20, 200) style:UITableViewStylePlain];
    contentTableView.backgroundColor = [UIColor clearColor];
    
    contentTableView.delegate = self;
    contentTableView.dataSource = self;
    
    contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:contentTableView];
    
    //设置按钮
    UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingBtn setBackgroundImage:[UIImage imageNamed:@"menu_action_400@2x"] forState:UIControlStateNormal];
    settingBtn.frame = CGRectMake(20, SCREEN_HEIGHT - 50, 40, 40);
    [settingBtn addTarget:self action:@selector(settingBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:settingBtn];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.contentArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"contentTableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 100, 30)];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont systemFontOfSize:16];
        label.text = self.contentArray[indexPath.row];
        [cell.contentView addSubview:label];
        cell.backgroundColor = [UIColor clearColor];
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
            if ([self.delegate respondsToSelector:@selector(SideMenuView:WillHeadToLike:)]) {
                [self.delegate SideMenuView:self WillHeadToLike:23];
            }
            break;
        case 1:
            
            break;
        case 2:
            
            break;
        case 3:
            
            break;
        case 4:
            
            break;

        default:
            break;
    }
}

/**
 *  设置
 */
-(void)settingBtnClick{
    if ([self.delegate respondsToSelector:@selector(SideMenuView:WillHeadToSetting:)]) {
        [self.delegate SideMenuView:self WillHeadToSetting:23];
    }
}

@end
